<template>
  <div class="dashboard-editor-container">
    <el-table v-loading="loading" :data="applyLogList">
      <el-table-column :label="$t('platformName')" align="center" prop="companyName"
                       v-if="!company || company.publicOpen == '0'">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 6">{{ scope.row.companyId }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ scope.row.companyId }}</span>
          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ scope.row.companyId }}</span>
          <span v-if="scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime)">{{
              scope.row.companyId
            }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ scope.row.companyId }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('loanAmount')" align="center" key="realApplyMoney" prop="realApplyMoney">
        <template slot-scope="scope">
              <span
                v-if="scope.row.status == 0 || scope.row.status == 1 || scope.row.status == 2 || scope.row.status == 3">0</span>
          <span
            v-if="scope.row.status == 6 || (scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime))">{{
              scope.row.realApplyMoney
            }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ scope.row.realApplyMoney }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ scope.row.realApplyMoney }}</span>
          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ scope.row.realApplyMoney }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="订单编号" align="center" key="orderSn" prop="orderSn"/>-->
      <el-table-column :label="$t('lendingTime')" align="center" prop="status">
        <template slot-scope="scope">
              <span
                v-if="scope.row.status == 6 || (scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime))">{{
                  parseTime(scope.row.applyTime)
                }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ parseTime(scope.row.applyTime) }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ parseTime(scope.row.applyTime) }}</span>
          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ parseTime(scope.row.applyTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('status')" align="center" prop="status">
        <template slot-scope="scope">
          <span v-if="scope.row.status == 6">{{ $t('orderStatus.repaymentInProgress') }}</span>

          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ $t("orderStatus.settle") }}</span>

          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ $t("orderStatus.overSettle") }}</span>

          <span v-if="scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime)">{{
              $t("orderStatus.settle")
            }}</span>

          <span v-if="scope.row.status == 8" style="color: red">{{ $t("orderStatus.overdueIng") }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('paymentAmount')" align="center" key="alreadyRepayMoney"
                       prop="alreadyRepayMoney">
        <template slot-scope="scope">
              <span
                v-if="scope.row.status == 6 || (scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime))">{{
                  scope.row.alreadyRepayMoney
                }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ scope.row.alreadyRepayMoney }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ scope.row.alreadyRepayMoney }}</span>
          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ scope.row.alreadyRepayMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('paymentTime')" align="center" prop="alreadyRepayTime">
        <template slot-scope="scope">
              <span
                v-if="scope.row.status == 6 || (scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime))">{{
                  parseTime(scope.row.alreadyRepayTime)
                }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ parseTime(scope.row.alreadyRepayTime) }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ parseTime(scope.row.alreadyRepayTime) }}</span>
          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ parseTime(scope.row.alreadyRepayTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('overdueTime')" align="center" key="repaymentTime" prop="repaymentTime">
        <template slot-scope="scope">
              <span
                v-if="scope.row.status == 6 || (scope.row.status == 7 && normal(scope.row.repaymentTime,scope.row.alreadyRepayTime))">{{
                  scope.row.repaymentTime
                }}</span>
          <span v-if="scope.row.status == 7 && dateFilter(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #af15c1">{{ scope.row.repaymentTime }}</span>
          <span v-if="scope.row.status == 8" style="color: red">{{ scope.row.repaymentTime }}</span>
          <span v-if="scope.row.status == 7 && compent(scope.row.repaymentTime,scope.row.alreadyRepayTime)"
                style="color: #c13a15">{{ scope.row.repaymentTime }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getApplyLogList"
    />
  </div>
</template>
<script>
import {listUserInfoApply} from "@/api/app/apply";
import {getCompanyDetail} from "@/api/company";

export default {
  data() {
    return {
      applyLogList: null,
      loading: false,
      total: 0,
      company: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10
      }
    }
  },
  methods: {
    /**
     * 公债明细
     * @param userId
     */
    getApplyLogList(userId) {
      this.loading = true;
      listUserInfoApply({userId: userId}).then(response => {
          this.applyLogList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },
    //根据用户获取公司详情
    getCompanyDetailByUserId() {
      getCompanyDetail().then(response => {
          this.company = response.data;
        }
      );
    },
    dateFilter(value1, value2) {
      value2 = value2.substr(0,10);
      const num1 = new Date(value1).getTime() / 1000;
      const num2 = new Date(value2).getTime() / 1000;
      return num1 - num2 >= 345600;
    },
    compent(value1, value2) {
      value2 = value2.substr(0,10);
      const num1 = new Date(value1).getTime() / 1000;
      const num2 = new Date(value2).getTime() / 1000;
      return num2 - num1 > 0;
    },
    normal(value1, value2) {
      value2 = value2.substr(0,10);
      const num1 = new Date(value1).getTime() / 1000;
      const num2 = new Date(value2).getTime() / 1000;
      return num1 - num2 < 345600 && num2 - num1 <= 0;
    }
  }
}
</script>
